package com.sqfw.project.wpReport.service.impl;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
import java.util.stream.Collectors;

import cn.hutool.core.thread.ThreadUtil;
import com.github.pagehelper.PageInfo;
import com.sqfw.common.constant.HttpStatus;
import com.sqfw.common.exception.base.BaseException;
import com.sqfw.common.utils.PageUtils;
import com.sqfw.common.utils.StringUtils;
import com.sqfw.framework.web.page.TableDataInfo;
import com.sqfw.project.system.domain.SysDept;
import com.sqfw.project.system.mapper.SysDeptMapper;
import com.sqfw.project.wp.domain.SysCode;
import com.sqfw.project.wp.domain.WpBackInfo;
import com.sqfw.project.wp.domain.WpHandleLog;
import com.sqfw.project.wp.domain.WpInfo;
import com.sqfw.project.wp.mapper.SysCodeMapper;
import com.sqfw.project.wp.mapper.WpBackInfoMapper;
import com.sqfw.project.wp.mapper.WpHandleLogMapper;
import com.sqfw.project.wp.mapper.WpInfoMapper;
import com.sqfw.project.wpReport.domain.WpHoliday;
import com.sqfw.project.wpReport.domain.WpInfoDetail;
import com.sqfw.project.wpReport.mapper.WpHolidayMapper;
import com.sqfw.project.wpReport.service.IWpInfoSummaryService;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import com.sqfw.project.wpReport.domain.WpInfoDept;
import com.sqfw.project.wpReport.service.IWpInfoDeptService;
import org.springframework.util.CollectionUtils;

/**
 * 三级承办单位处理情况汇总表Service业务层处理
 *
 * @author lx
 * @date 2023-07-11
 */
@Slf4j
@Service
public class WpInfoDeptServiceImpl implements IWpInfoDeptService {

    @Autowired
    private SysDeptMapper sysDeptMapper;

    @Autowired
    private WpHolidayMapper wpHolidayMapper;

    @Autowired
    private WpHandleLogMapper wpHandleLogMapper;

    @Autowired
    private WpBackInfoMapper wpBackInfoMapper;

    @Autowired
    private IWpInfoSummaryService wpInfoSummaryService;

    @Autowired
    private WpInfoMapper wpInfoMapper;

    @Autowired
    private SysCodeMapper sysCodeMapper;

    //三级承办单位顶级 pid  与数据库数据对应  三级承办单位
    private static final Long sysDeptPid = 1L;

    private static final Integer dayFive = 5;

    private static final Integer dayTen = 10;

    @Autowired
    @Qualifier(value = "asyncServiceExecutor")
    private Executor executor;


    @Override
    public List<WpInfoDept> getWpInfoDeptList(WpInfoDept wpInfoDept) {
        //查询节假日日期
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        long year = calendar.get(Calendar.YEAR);
        WpHoliday wpHoliday = new WpHoliday();
        wpHoliday.setYearid(year);

        List<WpHoliday> wpHolidays = wpHolidayMapper.selectWpHolidayList(wpHoliday);

        List<String> dates = wpHolidays.stream()
                .map(WpHoliday::getDtime)
                .map(simpleDateFormat::format)
                .collect(Collectors.toList());

        List<WpInfoDept> wpInfoDepts = new ArrayList<>();


        //承办单位id集合
        List<Long> deptList = new ArrayList<>();
        if (StringUtils.isNotEmpty(wpInfoDept.getMainUnitAll())) {
            List<String> mainUnitAll = wpInfoDept.getMainUnitAll();
            for (String mainUnit : mainUnitAll) {

                String[] split = mainUnit.split(",");
                if (split.length > 1) {
                    //SysDept sysDept = sysDeptMapper.selectDeptById(Long.valueOf(split[1]));
                    if (!deptList.contains(Long.valueOf(split[1]))) {
                        deptList.add(Long.valueOf(split[1]));
                    }

                } else if (split.length == 1) {
                    List<SysDept> depts = sysDeptMapper.selectChildrenDeptById(Long.valueOf(split[0]));
                    for (SysDept dept : depts) {
                        if (!deptList.contains(dept.getDeptId())) {
                            deptList.add(dept.getDeptId());
                        }
                    }
                    // deptList.addAll(depts);
                }
            }
        } else {
           /* SysDept dept = new SysDept();
            dept.setParentId(sysDeptPid);*/
            //获取三级承办单位下面的  中心  部门  处室  区县

            List<SysDept> sysDepts = sysDeptMapper.selectChildrenDeptById(sysDeptPid);
            List<Long> parentIds = sysDepts.stream().map(SysDept::getDeptId).collect(Collectors.toList());
            //获取所有承办单位集合

            List<SysDept> sysDeptList = sysDeptMapper.selectDeptListByParentIds(parentIds);
            List<Long> deptIdList = sysDeptList.stream().map(SysDept::getDeptId).collect(Collectors.toList());
            deptList.addAll(deptIdList);
        }

        //获取三级承办部门id集合
        List<String> deptLevel2s = deptList.stream()
                .map(String::valueOf)
                .collect(Collectors.toList());

        WpHandleLog wpHandleLogDept = new WpHandleLog();
        wpHandleLogDept.setDeptLevel2s(deptLevel2s);
        wpHandleLogDept.setBegainTime(wpInfoDept.getBegainTime());
        wpHandleLogDept.setEndTime(wpInfoDept.getEndTime());
        wpHandleLogDept.setNextState("承办单位处理");
        //过滤工单表中已删除的工单DEL_FLAG
        List<WpHandleLog> wpHandleLogList = wpHandleLogMapper.selectWpidListByDeptId(wpHandleLogDept);


        //初始化线程数量
        // CountDownLatch countDownLatch= ThreadUtil.newCountDownLatch(deptList.size());

        //创建异步阻塞任务集合
        List<CompletableFuture<List<WpInfoDept>>> futureList = new ArrayList<>();

        for (Long deptId : deptList) {

            futureList.add(CompletableFuture.supplyAsync(() -> getWpInfoDepts(deptId, wpHandleLogList, dates, wpInfoDept), executor));


        }

        //等待所有任务执行完成
        CompletableFuture.allOf(futureList.toArray(new CompletableFuture[0]));
        List<List<WpInfoDept>> collect = futureList.stream().map(CompletableFuture::join).collect(Collectors.toList());
        for (List<WpInfoDept> infoDepts : collect) {
            wpInfoDepts.addAll(infoDepts);
        }

        //唤醒主线程
      /*  try {
            countDownLatch.await();
        } catch (InterruptedException e) {
            log.info("报错：{}",e.toString());
        }*/

        List<WpInfoDept> infoDepts = wpInfoDepts.stream()
                .sorted(Comparator.comparing(WpInfoDept::getWpInfoCount).reversed())
                .collect(Collectors.toList());

        return infoDepts;
    }

    /**
     * 查询流转列表
     *
     * @param deptId
     * @param wpHandleLogList
     * @param dates
     * @param wpInfoDept
     * @return
     */
    private List<WpInfoDept> getWpInfoDepts(Long deptId, List<WpHandleLog> wpHandleLogList, List<String> dates, WpInfoDept wpInfoDept) {

        WpHandleLog wpHandleLogSe = new WpHandleLog();

        wpHandleLogSe.setBegainTime(wpInfoDept.getBegainTime());
        wpHandleLogSe.setEndTime(wpInfoDept.getEndTime());

        List<WpInfoDept> wpInfoDepts = new ArrayList<>();
        String deptIdString = deptId.toString();
        WpInfoDept wpInfoDeptCon = new WpInfoDept();

        List<WpHandleLog> handleLogs = wpHandleLogList.stream()
                .filter(handleLog -> (deptIdString).equals(handleLog.getNextDepartment1()))
                .collect(Collectors.toList());
        if (handleLogs.size() == 0) {
            return wpInfoDepts;
        }
        SysDept sysDept = sysDeptMapper.selectDeptById(deptId);
        wpInfoDeptCon.setDeptLevel2Name(sysDept.getDeptName());
        wpInfoDeptCon.setDeptLevel2(deptIdString);
        Set<String> wpInfoCountWpids = handleLogs.stream()
                .map(WpHandleLog::getWpid)
                .collect(Collectors.toSet());
        //派单总数
//        wpInfoDeptCon.setWpInfoCount(wpInfoCountWpids.size());
//        wpInfoDeptCon.setWpInfoCountWpids(new ArrayList<>(wpInfoCountWpids));

        //未办结
        wpHandleLogSe.setNextDepartment1(deptIdString);
        //过滤工单表中已删除的工单DEL_FLAG
        List<String> unCompletingCountWpidsCon = wpHandleLogMapper.selectUnCompletingCountWpidsByDept(wpHandleLogSe);
        List<String> unCompletingCountWpids = new ArrayList<>();
        for (String wpidCon : unCompletingCountWpidsCon) {
            WpHandleLog wpHandleLogCon = new WpHandleLog();
            wpHandleLogCon.setNextDepartment1(deptIdString);
            wpHandleLogCon.setWpid(wpidCon);
            wpHandleLogCon.setBegainTime(wpInfoDept.getBegainTime());
            wpHandleLogCon.setEndTime(wpInfoDept.getEndTime());
            List<WpHandleLog> wpHandleLogs = wpHandleLogMapper.selectWpHandleLogList(wpHandleLogCon);
            WpHandleLog wpHandleLog1 = wpHandleLogs.stream().filter(wpHandleLog -> "承办单位处理".equals(wpHandleLog.getNextState())).max(Comparator.comparing(WpHandleLog::getUpdateTime)).orElse(null);

            if (wpHandleLog1 != null && StringUtils.isEmpty(wpHandleLog1.getHfState())) {
                unCompletingCountWpids.add(wpidCon);
            }
        }

       /* //5天办结
        wpHandleLogSe.setHfState("1");
        List<String> wpidsFive = wpHandleLogMapper.selectwpidsCompleteDayByDept(wpHandleLogSe);

        List<WpHandleLog> wpHandleLogsNew = wpHandleLogMapper.selectwpidsCompleteDayByDeptNew(wpHandleLogSe);
        //10天办结
        wpHandleLogSe.setHfState("2");
        List<String> wpidsTen = wpHandleLogMapper.selectwpidsCompleteDayByDept(wpHandleLogSe);

        //超时办结
        wpHandleLogSe.setHfState("3");
        List<String> wpidsTimeoutComplete = wpHandleLogMapper.selectwpidsCompleteDayByDept(wpHandleLogSe);*/

        //过滤工单表中已删除的工单DEL_FLAG
        List<WpHandleLog> wpHandleLogsNew = wpHandleLogMapper.selectwpidsCompleteDayByDeptNew(wpHandleLogSe);

        List<String> wpidsFive = wpHandleLogsNew.stream().filter(logNew -> "1".equals(logNew.getHfState())).map(WpHandleLog::getWpid).collect(Collectors.toList());

        List<String> wpidsTen = wpHandleLogsNew.stream().filter(logNew -> "2".equals(logNew.getHfState())).map(WpHandleLog::getWpid).collect(Collectors.toList());

        List<String> wpidsTimeoutComplete = wpHandleLogsNew.stream().filter(logNew -> "3".equals(logNew.getHfState())).map(WpHandleLog::getWpid).collect(Collectors.toList());

        //5天办结数
        wpInfoDeptCon.setFiveCompleteCount(wpidsFive.size());
        wpInfoDeptCon.setFiveCompleteCountWpids(wpidsFive);
        //10天办结数
        wpInfoDeptCon.setTenCompleteCount(wpidsTen.size());
        wpInfoDeptCon.setTenCompleteCountWpids(wpidsTen);

        //按时办结总数
        List<String> wpidsOntime = new ArrayList<>();
        //按时办结数
        wpidsOntime.addAll(wpidsFive);
        wpidsOntime.addAll(wpidsTen);

        if (wpidsOntime.size() > wpInfoCountWpids.size()) {
            wpInfoDeptCon.setOntimeCompleteCount(wpInfoCountWpids.size());
        } else {
            wpInfoDeptCon.setOntimeCompleteCount(wpidsOntime.size());
        }
        wpInfoDeptCon.setOntimeCompleteCountWpids(wpidsOntime);

        //超时已完成
        wpInfoDeptCon.setTimeoutCompleteCount(wpidsTimeoutComplete.size());
        wpInfoDeptCon.setTimeoutCompleteCountWpids(wpidsTimeoutComplete);

        //超时未完结
        List<String> timeoutUncompleteCountWpids = new ArrayList<>();

        //处理中
        List<String> completingCountWpids = new ArrayList<>();

        SimpleDateFormat formatCon = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        Date date = new Date();

        WpBackInfo wpBackInfo = new WpBackInfo();
        wpBackInfo.setBegainTime(wpInfoDept.getBegainTime());
        wpBackInfo.setEndTime(wpInfoDept.getEndTime());
        wpBackInfo.setDeptLevel2(String.valueOf(sysDept.getDeptId()));
        wpBackInfo.setState("审核人收回工单");
        wpBackInfo.setNextState("审核人处理");
        //过滤工单表中已删除的工单DEL_FLAG
        List<String> recoverCountWpids = wpBackInfoMapper.selectRecoverCountWpids(wpBackInfo);

        wpInfoDeptCon.setRecoverCount(recoverCountWpids.size());
        wpInfoDeptCon.setRecoverCountWpids(recoverCountWpids);
        /** 逻辑有变动 */
//        //总量
//        List<String> wpidsNew = new ArrayList<>();
//        if (recoverCountWpids.size()>0){
//            for (String recoverCountWpid : recoverCountWpids) {
//
//                    WpHandleLog wpHandleLog = new WpHandleLog();
//                    wpHandleLog.setWpid(recoverCountWpid);
//                    wpHandleLog.setBegainTime(wpInfoDept.getBegainTime());
//                    wpHandleLog.setEndTime(wpInfoDept.getEndTime());
//                    List<WpHandleLog> wpHandleLogs = wpHandleLogMapper.selectWpHandleLogListByWpidAndTime(wpHandleLog);
//                    WpHandleLog wpHandleLog1 = wpHandleLogs.stream().filter(dto -> "承办单位处理".equals(dto.getNextState()))
//                            .max(Comparator.comparing(WpHandleLog::getUpdateTime)).orElse(null);
//
//                    WpHandleLog wpHandleLog2 = wpHandleLogs.stream().filter(dto -> "审核人收回工单".equals(dto.getLastState()))
//                            .max(Comparator.comparing(WpHandleLog::getUpdateTime)).orElse(null);
//                    if (wpHandleLog1!=null&&wpHandleLog2!=null&&wpHandleLog2.getUpdateTime().compareTo(wpHandleLog1.getUpdateTime())>0){
//
//                        wpidsNew.add(recoverCountWpid);
//                    }
//                    if (wpHandleLog1!=null&&wpHandleLog2!=null&&wpHandleLog2.getUpdateTime().compareTo(wpHandleLog1.getUpdateTime())<0&&StringUtils.isNotEmpty(wpHandleLog1.getNextDepartment1())
//                            &&!wpHandleLog1.getNextDepartment1().equals(String.valueOf(deptId))){
//                        wpidsNew.add(recoverCountWpid);
//                    }
//
//
//            }
//        }
//        wpInfoDeptCon.setWpInfoCount(wpInfoCountWpids.size()-wpidsNew.size());
        // 承办单位已处理工单列表(通过轨迹表查询)--派单数
        WpInfo queryWpInfo = new WpInfo();
        queryWpInfo.setBegainTime(wpInfoDept.getBegainTime());
        queryWpInfo.setEndTime(wpInfoDept.getEndTime());
        queryWpInfo.setDeptLevel2(deptId.toString());
        List<WpInfo> wpidList = wpInfoMapper.selectProcessedCBWpInfoList(queryWpInfo);
        if (!CollectionUtils.isEmpty(wpidList)) {
            List<String> wpids = wpidList.stream().map(WpInfo::getWpid).collect(Collectors.toList());
            wpInfoDeptCon.setWpInfoCount(wpids.size());
            wpInfoDeptCon.setWpInfoCountWpids(wpids);
        }else {
            wpInfoDeptCon.setWpInfoCount(0);
        }

        //未办结
        for (String unCompletingCountWpid : unCompletingCountWpids) {
            //已经撤回了
            if (recoverCountWpids.contains(unCompletingCountWpid)) {
                WpHandleLog wpHandleLog = new WpHandleLog();
                wpHandleLog.setWpid(unCompletingCountWpid);
                wpHandleLog.setBegainTime(wpInfoDept.getBegainTime());
                wpHandleLog.setEndTime(wpInfoDept.getEndTime());
                List<WpHandleLog> wpHandleLogs = wpHandleLogMapper.selectWpHandleLogListByWpidAndTime(wpHandleLog);
                WpHandleLog wpHandleLog1 = wpHandleLogs.stream().filter(dto -> "承办单位处理".equals(dto.getNextState()))
                        .max(Comparator.comparing(WpHandleLog::getUpdateTime)).orElse(null);

                WpHandleLog wpHandleLog2 = wpHandleLogs.stream().filter(dto -> "审核人收回工单".equals(dto.getLastState()))
                        .max(Comparator.comparing(WpHandleLog::getUpdateTime)).orElse(null);

                if (wpHandleLog1 != null && wpHandleLog2 != null) {
                    if (wpHandleLog2.getUpdateTime().compareTo(wpHandleLog1.getUpdateTime())<0){
                        if (StringUtils.isNotEmpty(wpHandleLog2.getNextDepartment1())
                                &&StringUtils.isNotEmpty(wpHandleLog1.getNextDepartment1())
                                &&wpHandleLog2.getNextDepartment1().equals(wpHandleLog1.getNextDepartment1())){

                        }else {
                            continue;
                        }
                    }else {
                        continue;
                    }

                }

            }

            try {
                WpInfo wpInfo = wpInfoMapper.selectWpInfoByWpId(unCompletingCountWpid);
                if (StringUtils.isNotEmpty(wpInfo.getTimeBoundry())) {
                    Date parse = formatCon.parse(wpInfo.getTimeBoundry());
                    if (parse.compareTo(date) > 0) {
                        completingCountWpids.add(unCompletingCountWpid);
                        continue;
                    }
                }

                WpHandleLog wpHandleLogCon = new WpHandleLog();
                wpHandleLogCon.setWpid(unCompletingCountWpid);
                wpHandleLogCon.setNextState("承办单位处理");
                wpHandleLogCon.setNextDepartment1(deptIdString);
                //工单轨迹记录
                List<WpHandleLog> wpHandleLogs = wpHandleLogMapper.selectWpHandleLogList(wpHandleLogCon);
                //承办单位处理
                WpHandleLog logCon = wpHandleLogs.stream()
                        .max(Comparator.comparing(WpHandleLog::getUpdateTime))
                        .orElse(null);
                if (logCon == null) {
                    log.info("工单编号：{}，部门id：{}", unCompletingCountWpid, deptIdString);
                    throw new BaseException("承办单位已完成工单数据异常");
                }
                Date updateTime = logCon.getUpdateTime();
                Date time = checkOntime(updateTime, dayTen, dates);

                if (time.compareTo(date) >= 0) {
                    completingCountWpids.add(unCompletingCountWpid);
                } else {
                    //超时未完成
                    timeoutUncompleteCountWpids.add(unCompletingCountWpid);
                }
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
        //按时处理中
        wpInfoDeptCon.setCompletingCount(completingCountWpids.size());
        wpInfoDeptCon.setCompletingCountWpids(completingCountWpids);
        //超时未完成
        wpInfoDeptCon.setTimeoutUncompleteCount(timeoutUncompleteCountWpids.size());
        wpInfoDeptCon.setTimeoutUncompleteCountWpids(timeoutUncompleteCountWpids);

        //延期工单数 = 超时未完成(TimeoutUncompleteCount) + 超时已完成(timeoutCompleteCount)
        wpInfoDeptCon.setDelayCount(wpInfoDeptCon.getTimeoutCompleteCount()+wpInfoDeptCon.getTimeoutUncompleteCount());

        wpInfoDepts.add(wpInfoDeptCon);
        return wpInfoDepts;

    }


    @Override
    public TableDataInfo getWpInfoListByWpids(WpInfo wpInfo) {


        String type = wpInfo.getType();
        if (StringUtils.isEmpty(type)) {
            throw new BaseException("参数异常，请确认");
        }

        List<WpInfo> wpInfoList = new ArrayList<>();

        TableDataInfo tableDataInfo = new TableDataInfo();
        tableDataInfo.setCode(HttpStatus.SUCCESS);
        tableDataInfo.setMsg("查询成功！");

        if ("wpInfoCount".equals(type)) {

//            List<WpInfo> list = wpInfoMapper.selectWpinfoByDept(wpInfo);
//            List<String> wpids = list.stream()
//                    .map(WpInfo::getWpid).collect(Collectors.toList());
//
//            WpBackInfo wpBackInfo = new WpBackInfo();
//            wpBackInfo.setBegainTime(wpInfo.getBegainTime());
//            wpBackInfo.setEndTime(wpInfo.getEndTime());
//            wpBackInfo.setDeptLevel2(String.valueOf(wpInfo.getDeptLevel2()));
//            wpBackInfo.setState("审核人收回工单");
//            wpBackInfo.setNextState("审核人处理");
//            List<String> recoverCountWpids = wpBackInfoMapper.selectRecoverCountWpids(wpBackInfo);
//
//            //总量
//            List<String> wpidsNew = new ArrayList<>();
//            if (recoverCountWpids.size()>0){
//                for (String recoverCountWpid : recoverCountWpids) {
//                    WpHandleLog wpHandleLog = new WpHandleLog();
//                    wpHandleLog.setWpid(recoverCountWpid);
//                    wpHandleLog.setBegainTime(wpInfo.getBegainTime());
//                    wpHandleLog.setEndTime(wpInfo.getEndTime());
//                    List<WpHandleLog> wpHandleLogs = wpHandleLogMapper.selectWpHandleLogListByWpidAndTime(wpHandleLog);
//                    WpHandleLog wpHandleLog1 = wpHandleLogs.stream().filter(dto -> "承办单位处理".equals(dto.getNextState()))
//                            .max(Comparator.comparing(WpHandleLog::getUpdateTime)).orElse(null);
//
//                    WpHandleLog wpHandleLog2 = wpHandleLogs.stream().filter(dto -> "审核人收回工单".equals(dto.getLastState()))
//                            .max(Comparator.comparing(WpHandleLog::getUpdateTime)).orElse(null);
//                    if (wpHandleLog1!=null&&wpHandleLog2!=null&&wpHandleLog2.getUpdateTime().compareTo(wpHandleLog1.getUpdateTime())>0){
//                        wpidsNew.add(recoverCountWpid);
//                    }
//                    if (wpHandleLog1!=null&&wpHandleLog2!=null&&wpHandleLog2.getUpdateTime().compareTo(wpHandleLog1.getUpdateTime())<0&&StringUtils.isNotEmpty(wpHandleLog1.getNextDepartment1())
//                            &&!wpHandleLog1.getNextDepartment1().equals(wpInfo.getDeptLevel2())){
//                        wpidsNew.add(recoverCountWpid);
//                    }
//                }
//            }
//          // tableDataInfo.setTotal(new PageInfo(list).getTotal());
//            if (wpidsNew.size()>0){
//                wpids.removeAll(wpidsNew);
//            }
//            if (wpids.size() == 0) {
//                tableDataInfo.setRows(wpInfoList);
//                return tableDataInfo;
//            }
            // 承办单位已处理工单
            List<WpInfo> wpidList = wpInfoMapper.selectProcessedCBWpInfoList(wpInfo);
            if (!CollectionUtils.isEmpty(wpidList)) {
                List<String> wpids = wpidList.stream()
                    .map(WpInfo::getWpid).collect(Collectors.toList());
                List<WpInfo> wpInfos = wpInfoMapper.selectWpInfoByWpids(wpids);
                wpInfoList.addAll(wpInfos);
            }
        } else if ("fiveCompleteCount".equals(type)) {

           WpHandleLog wpHandleLogSe = new WpHandleLog();
           wpHandleLogSe.setBegainTime(wpInfo.getBegainTime());
           wpHandleLogSe.setEndTime(wpInfo.getEndTime());
           wpHandleLogSe.setNextDepartment1(wpInfo.getDeptLevel2());
            wpHandleLogSe.setWpid(wpInfo.getWpid());
            wpHandleLogSe.setPhoneno(wpInfo.getPhoneno());
            List<WpHandleLog> wpHandleLogsNew = wpHandleLogMapper.selectwpidsCompleteDayByDeptNew2(wpHandleLogSe);

            List<String> wpidsFive = wpHandleLogsNew.stream().filter(logNew -> "1".equals(logNew.getHfState())).map(WpHandleLog::getWpid).collect(Collectors.toList());

          /*  //5天办结数
            wpInfo.setHfState("1");
            List<WpInfo> list = wpInfoMapper.selectWpinfoByDept(wpInfo);
            List<String> wpids = list.stream()
                    .map(WpInfo::getWpid).collect(Collectors.toList());
            tableDataInfo.setTotal(new PageInfo(list).getTotal());*/
            if (wpidsFive.size() == 0) {
                tableDataInfo.setRows(wpInfoList);
                return tableDataInfo;
            }
            List<WpInfo> wpInfos = wpInfoMapper.selectWpInfoByWpids(wpidsFive);
            wpInfoList.addAll(wpInfos);

        } else if ("tenCompleteCount".equals(type)) {
            //10天办结数

           /* wpInfo.setHfState("2");
            List<WpInfo> list = wpInfoMapper.selectWpinfoByDept(wpInfo);
            List<String> wpids = list.stream()
                    .map(WpInfo::getWpid).collect(Collectors.toList());
            tableDataInfo.setTotal(new PageInfo(list).getTotal());*/

            WpHandleLog wpHandleLogSe = new WpHandleLog();
            wpHandleLogSe.setBegainTime(wpInfo.getBegainTime());
            wpHandleLogSe.setEndTime(wpInfo.getEndTime());
            wpHandleLogSe.setNextDepartment1(wpInfo.getDeptLevel2());
            wpHandleLogSe.setWpid(wpInfo.getWpid());
            wpHandleLogSe.setPhoneno(wpInfo.getPhoneno());
            List<WpHandleLog> wpHandleLogsNew = wpHandleLogMapper.selectwpidsCompleteDayByDeptNew2(wpHandleLogSe);

            List<String> wpidsTen = wpHandleLogsNew.stream().filter(logNew -> "2".equals(logNew.getHfState())).map(WpHandleLog::getWpid).collect(Collectors.toList());

            if (wpidsTen.size() == 0) {
                tableDataInfo.setRows(wpInfoList);
                return tableDataInfo;
            }
            List<WpInfo> wpInfos = wpInfoMapper.selectWpInfoByWpids(wpidsTen);
            wpInfoList.addAll(wpInfos);

        } else if ("ontimeCompleteCount".equals(type)) {
            //按时办结数
           /* List<String> hfStates = new ArrayList<>();
            hfStates.add("1");
            hfStates.add("2");
            wpInfo.setHfStates(hfStates);
            List<WpInfo> list = wpInfoMapper.selectWpinfoByDept(wpInfo);
            List<String> wpids = list.stream()
                    .map(WpInfo::getWpid).collect(Collectors.toList());
            tableDataInfo.setTotal(new PageInfo(list).getTotal());*/

            List<String> wpids = new ArrayList<>();
            WpHandleLog wpHandleLogSe = new WpHandleLog();
            wpHandleLogSe.setBegainTime(wpInfo.getBegainTime());
            wpHandleLogSe.setEndTime(wpInfo.getEndTime());
            wpHandleLogSe.setNextDepartment1(wpInfo.getDeptLevel2());
            wpHandleLogSe.setWpid(wpInfo.getWpid());
            wpHandleLogSe.setPhoneno(wpInfo.getPhoneno());
            List<WpHandleLog> wpHandleLogsNew = wpHandleLogMapper.selectwpidsCompleteDayByDeptNew2(wpHandleLogSe);

            List<String> wpidsFive = wpHandleLogsNew.stream().filter(logNew -> "1".equals(logNew.getHfState())).map(WpHandleLog::getWpid).collect(Collectors.toList());

            List<String> wpidsTen = wpHandleLogsNew.stream().filter(logNew -> "2".equals(logNew.getHfState())).map(WpHandleLog::getWpid).collect(Collectors.toList());
            wpids.addAll(wpidsFive);
            wpids.addAll(wpidsTen);

            if (wpids.size() == 0) {
                tableDataInfo.setRows(wpInfoList);
                return tableDataInfo;
            }
            List<WpInfo> wpInfos = wpInfoMapper.selectWpInfoByWpids(wpids);
            wpInfoList.addAll(wpInfos);
        } else if ("timeoutCompleteCount".equals(type)) {
            //超时已办结
            /*wpInfo.setHfState("3");
            List<WpInfo> list = wpInfoMapper.selectWpinfoByDept(wpInfo);
            List<String> wpids = list.stream()
                    .map(WpInfo::getWpid).collect(Collectors.toList());
            tableDataInfo.setTotal(new PageInfo(list).getTotal());*/

           // List<String> wpids = new ArrayList<>();
            WpHandleLog wpHandleLogSe = new WpHandleLog();
            wpHandleLogSe.setBegainTime(wpInfo.getBegainTime());
            wpHandleLogSe.setEndTime(wpInfo.getEndTime());
            wpHandleLogSe.setNextDepartment1(wpInfo.getDeptLevel2());
            wpHandleLogSe.setWpid(wpInfo.getWpid());
            wpHandleLogSe.setPhoneno(wpInfo.getPhoneno());
            List<WpHandleLog> wpHandleLogsNew = wpHandleLogMapper.selectwpidsCompleteDayByDeptNew2(wpHandleLogSe);

            List<String> wpidsOut = wpHandleLogsNew.stream().filter(logNew -> "3".equals(logNew.getHfState())).map(WpHandleLog::getWpid).collect(Collectors.toList());

            if (wpidsOut.size() == 0) {
                tableDataInfo.setRows(wpInfoList);
                return tableDataInfo;
            }
            List<WpInfo> wpInfos = wpInfoMapper.selectWpInfoByWpids(wpidsOut);
            wpInfoList.addAll(wpInfos);

        } else if ("timeoutUncompleteCount".equals(type)) {
            //超时未办结

        } else if ("delayCount".equals(type)) {
            //延期工单数 = 超时已办结 + 超时未完结
            //超时已完成
            List<String> delayWpids = new ArrayList<>();
            WpHandleLog wpHandleLogSe = new WpHandleLog();
            wpHandleLogSe.setBegainTime(wpInfo.getBegainTime());
            wpHandleLogSe.setEndTime(wpInfo.getEndTime());
            wpHandleLogSe.setNextDepartment1(wpInfo.getDeptLevel2());
            wpHandleLogSe.setWpid(wpInfo.getWpid());
            wpHandleLogSe.setPhoneno(wpInfo.getPhoneno());
            List<WpHandleLog> wpHandleLogsNew = wpHandleLogMapper.selectwpidsCompleteDayByDeptNew2(wpHandleLogSe);
            List<String> wpidsOut = wpHandleLogsNew.stream().filter(logNew -> "3".equals(logNew.getHfState())).map(WpHandleLog::getWpid).collect(Collectors.toList());
            delayWpids.addAll(wpidsOut);
            //超时未完结
            List<String> timeoutUncompleteCountWpids = new ArrayList<>();
            List<String> unCompletingCountWpidsCon = wpHandleLogMapper.selectUnCompletingCountWpidsByDept(wpHandleLogSe);
            List<String> unCompletingCountWpids = new ArrayList<>();
            for (String wpidCon : unCompletingCountWpidsCon) {
                WpHandleLog wpHandleLogCon = new WpHandleLog();
                wpHandleLogCon.setNextDepartment1(wpInfo.getDeptLevel2());
                wpHandleLogCon.setWpid(wpidCon);
                wpHandleLogCon.setBegainTime(wpInfo.getBegainTime());
                wpHandleLogCon.setEndTime(wpInfo.getEndTime());
                List<WpHandleLog> wpHandleLogs = wpHandleLogMapper.selectWpHandleLogList(wpHandleLogCon);
                WpHandleLog wpHandleLog1 = wpHandleLogs.stream().filter(wpHandleLog -> "承办单位处理".equals(wpHandleLog.getNextState())).max(Comparator.comparing(WpHandleLog::getUpdateTime)).orElse(null);

                if (wpHandleLog1 != null && StringUtils.isEmpty(wpHandleLog1.getHfState())) {
                    unCompletingCountWpids.add(wpidCon);
                }
            }
            //处理中
            List<String> completingCountWpids = new ArrayList<>();

            SimpleDateFormat formatCon = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

            Date date = new Date();

            WpBackInfo wpBackInfo = new WpBackInfo();
            wpBackInfo.setBegainTime(wpInfo.getBegainTime());
            wpBackInfo.setEndTime(wpInfo.getEndTime());
            wpBackInfo.setDeptLevel2(wpInfo.getDeptLevel2());
            wpBackInfo.setState("审核人收回工单");
            wpBackInfo.setNextState("审核人处理");
            //过滤工单表中已删除的工单DEL_FLAG
            List<String> recoverCountWpids = wpBackInfoMapper.selectRecoverCountWpids(wpBackInfo);
            for (String unCompletingCountWpid : unCompletingCountWpids) {
                //已经撤回了
                if (recoverCountWpids.contains(unCompletingCountWpid)) {
                    WpHandleLog wpHandleLog = new WpHandleLog();
                    wpHandleLog.setWpid(unCompletingCountWpid);
                    wpHandleLog.setBegainTime(wpInfo.getBegainTime());
                    wpHandleLog.setEndTime(wpInfo.getEndTime());
                    List<WpHandleLog> wpHandleLogs = wpHandleLogMapper.selectWpHandleLogListByWpidAndTime(wpHandleLog);
                    WpHandleLog wpHandleLog1 = wpHandleLogs.stream().filter(dto -> "承办单位处理".equals(dto.getNextState()))
                            .max(Comparator.comparing(WpHandleLog::getUpdateTime)).orElse(null);

                    WpHandleLog wpHandleLog2 = wpHandleLogs.stream().filter(dto -> "审核人收回工单".equals(dto.getLastState()))
                            .max(Comparator.comparing(WpHandleLog::getUpdateTime)).orElse(null);

                    if (wpHandleLog1 != null && wpHandleLog2 != null) {
                        if (wpHandleLog2.getUpdateTime().compareTo(wpHandleLog1.getUpdateTime())<0){
                            if (StringUtils.isNotEmpty(wpHandleLog2.getNextDepartment1())
                                    &&StringUtils.isNotEmpty(wpHandleLog1.getNextDepartment1())
                                    &&wpHandleLog2.getNextDepartment1().equals(wpHandleLog1.getNextDepartment1())){

                            }else {
                                continue;
                            }
                        }else {
                            continue;
                        }

                    }

                }

                try {
                     //查询节假日日期
                    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
                    Calendar calendar = Calendar.getInstance();
                    calendar.setTime(new Date());
                    long year = calendar.get(Calendar.YEAR);
                    WpHoliday wpHoliday = new WpHoliday();
                    wpHoliday.setYearid(year);

                    List<WpHoliday> wpHolidays = wpHolidayMapper.selectWpHolidayList(wpHoliday);

                    List<String> dates = wpHolidays.stream()
                            .map(WpHoliday::getDtime)
                            .map(simpleDateFormat::format)
                            .collect(Collectors.toList());


                    WpInfo info = wpInfoMapper.selectWpInfoByWpId(unCompletingCountWpid);
                    if (StringUtils.isNotEmpty(info.getTimeBoundry())) {
                        Date parse = formatCon.parse(info.getTimeBoundry());
                        if (parse.compareTo(date) > 0) {
                            completingCountWpids.add(unCompletingCountWpid);
                            continue;
                        }
                    }

                    WpHandleLog wpHandleLogCon = new WpHandleLog();
                    wpHandleLogCon.setWpid(unCompletingCountWpid);
                    wpHandleLogCon.setNextState("承办单位处理");
                    wpHandleLogCon.setNextDepartment1(wpInfo.getDeptLevel2());
                    //工单轨迹记录
                    List<WpHandleLog> wpHandleLogs = wpHandleLogMapper.selectWpHandleLogList(wpHandleLogCon);
                    //承办单位处理
                    WpHandleLog logCon = wpHandleLogs.stream()
                            .max(Comparator.comparing(WpHandleLog::getUpdateTime))
                            .orElse(null);
                    if (logCon == null) {
                        log.info("工单编号：{}，部门id：{}", unCompletingCountWpid, wpInfo.getDeptLevel2());
                        throw new BaseException("承办单位已完成工单数据异常");
                    }
                    Date updateTime = logCon.getUpdateTime();
                    Date time = checkOntime(updateTime, dayTen, dates);

                    if (time.compareTo(date) >= 0) {
                        completingCountWpids.add(unCompletingCountWpid);
                    } else {
                        //超时未完成
                        timeoutUncompleteCountWpids.add(unCompletingCountWpid);
                    }
                } catch (ParseException e) {
                    e.printStackTrace();
                }
            }

            delayWpids.addAll(timeoutUncompleteCountWpids);
            if (delayWpids.size() == 0) {
                tableDataInfo.setRows(wpInfoList);
                return tableDataInfo;
            }
            List<WpInfo> wpInfos = wpInfoMapper.selectWpInfoByWpids(delayWpids);
            wpInfoList.addAll(wpInfos);

        } else if ("completingCount".equals(type)) {
            //按时处理中

        } else if ("recoverCount".equals(type)) {
            //收回工单数
            WpBackInfo wpBackInfo = new WpBackInfo();
            wpBackInfo.setBegainTime(wpInfo.getBegainTime());
            wpBackInfo.setEndTime(wpInfo.getEndTime());
            wpBackInfo.setDeptLevel2(wpInfo.getDeptLevel2());
            wpBackInfo.setState("审核人收回工单");
            wpBackInfo.setNextState("审核人处理");
            wpBackInfo.setWpid(wpInfo.getWpid());
            List<String> recoverCountWpids = wpBackInfoMapper.selectRecoverCountWpids(wpBackInfo);
           // tableDataInfo.setTotal(new PageInfo(recoverCountWpids).getTotal());
            if (recoverCountWpids.size() == 0) {
                tableDataInfo.setRows(wpInfoList);
                return tableDataInfo;
            }
            List<WpInfo> wpInfos = wpInfoMapper.selectWpInfoByWpids(recoverCountWpids);
            wpInfoList.addAll(wpInfos);


        }
        //创建异步阻塞任务集合
        List<CompletableFuture<WpInfo>> futureList = new ArrayList<>();

        for (WpInfo info : wpInfoList) {

            futureList.add(CompletableFuture.supplyAsync(() -> getWpInfoList(info), executor));


        }
        List<WpInfo> collect = futureList.stream().map(CompletableFuture::join).collect(Collectors.toList());
        tableDataInfo.setRows(collect);
        return tableDataInfo;
    }


    public WpInfo getWpInfoList(WpInfo info){
        String class1 = info.getClass1();
        String class2 = info.getClass2();
        String class3 = info.getClass3();
        String class4 = info.getClass4();

        StringBuffer name = new StringBuffer();

        if (StringUtils.isNotEmpty(class1)) {
            SysCode sysCode = sysCodeMapper.selectSysCodeByAutoId(Long.valueOf(class1));
            if (sysCode != null) {
                info.setMainNodename(sysCode.getNodename());
            }
        }

        if (StringUtils.isNotEmpty(class2)) {
            SysCode sysCode = sysCodeMapper.selectSysCodeByAutoId(Long.valueOf(class2));
            if (sysCode != null) {
                name.append(sysCode.getNodename());
            }
        }
        if (StringUtils.isNotEmpty(class3)) {
            SysCode sysCode = sysCodeMapper.selectSysCodeByAutoId(Long.valueOf(class3));
            if (sysCode != null) {
                name.append("/").append(sysCode.getNodename());
            }
        }
        if (StringUtils.isNotEmpty(class4)) {
            SysCode sysCode = sysCodeMapper.selectSysCodeByAutoId(Long.valueOf(class4));
            if (sysCode != null) {
                name.append("/").append(sysCode.getNodename());
            }
        }
        if (StringUtils.isNotEmpty(name)) {
            info.setChildNodeName(name.toString());
        }
        return info;
    }
    @Override
    public List<String> selectWpInfoListByWpids(WpInfo wpInfo) {
        String type = wpInfo.getType();
        List<String> wpInfosList = new ArrayList<>();
        List<String> wpids = wpInfoMapper.selectWpinfoByDeptAndHfState(wpInfo).stream()
                .map(WpInfo::getWpid).collect(Collectors.toList());
        if (wpids.size() == 0) {
            return wpInfosList;
        }
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //查询节假日日期
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        long year = calendar.get(Calendar.YEAR);
        WpHoliday wpHoliday = new WpHoliday();
        wpHoliday.setYearid(year);

        List<WpHoliday> wpHolidays = wpHolidayMapper.selectWpHolidayList(wpHoliday);

        List<String> dates = wpHolidays.stream()
                .map(WpHoliday::getDtime)
                .map(simpleDateFormat::format)
                .collect(Collectors.toList());


        if ("timeoutUncompleteCount".equals(type)) {
            //超时未办结

            for (String unCompletingCountWpid : wpids) {
                Boolean flag = this.checkWpid(unCompletingCountWpid, wpInfo.getBegainTime(), wpInfo.getEndTime());
                if (flag) {
                    continue;
                }
                WpHandleLog wpHandleLogCon = new WpHandleLog();
                wpHandleLogCon.setWpid(unCompletingCountWpid);
                wpHandleLogCon.setNextState("承办单位处理");
                wpHandleLogCon.setNextDepartment1(wpInfo.getDeptLevel2());
                //工单轨迹记录
                List<WpHandleLog> wpHandleLogs = wpHandleLogMapper.selectWpHandleLogList(wpHandleLogCon);
                //承办单位处理
                WpHandleLog logCon = wpHandleLogs.stream()
                        .max(Comparator.comparing(WpHandleLog::getUpdateTime))
                        .orElse(null);
                if (logCon == null) {
                    throw new BaseException("承办单位已完成工单数据异常");
                }
                Date updateTime = logCon.getUpdateTime();
                Date time = checkOntime(updateTime, dayTen, dates);
                Date date = new Date();

                WpInfo info = wpInfoMapper.selectWpInfoByWpId(unCompletingCountWpid);
                if (StringUtils.isNotEmpty(info.getTimeBoundry())) {
                    try {
                        Date parse = dateFormat.parse(info.getTimeBoundry());
                        if (time.compareTo(date) < 0 && date.compareTo(parse) > 0) {
                            wpInfosList.add(unCompletingCountWpid);
                        }
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                }


            }

        } else if ("completingCount".equals(type)) {
            //按时处理中

            for (String unCompletingCountWpid : wpids) {
                Boolean flag = this.checkWpid(unCompletingCountWpid, wpInfo.getBegainTime(), wpInfo.getEndTime());
                if (flag) {
                    continue;
                }
                WpHandleLog wpHandleLogCon = new WpHandleLog();
                wpHandleLogCon.setWpid(unCompletingCountWpid);
                wpHandleLogCon.setNextState("承办单位处理");
                wpHandleLogCon.setNextDepartment1(wpInfo.getDeptLevel2());
                //工单轨迹记录
                List<WpHandleLog> wpHandleLogs = wpHandleLogMapper.selectWpHandleLogList(wpHandleLogCon);
                //承办单位处理
                WpHandleLog logCon = wpHandleLogs.stream()
                        .max(Comparator.comparing(WpHandleLog::getUpdateTime))
                        .orElse(null);
                if (logCon == null) {
                    throw new BaseException("承办单位已完成工单数据异常");
                }
                WpInfo info = wpInfoMapper.selectWpInfoByWpId(unCompletingCountWpid);
                Date updateTime = logCon.getUpdateTime();
                Date time = checkOntime(updateTime, dayTen, dates);
                try {
                    if (StringUtils.isNotEmpty(info.getTimeBoundry())) {
                        Date parse = dateFormat.parse(info.getTimeBoundry());
                        Date date = new Date();
                        if (time.compareTo(new Date()) >= 0 || date.compareTo(parse) < 0) {
                            wpInfosList.add(unCompletingCountWpid);
                        }
                    }

                } catch (ParseException e) {
                    e.printStackTrace();
                }
            }


        }

        return wpInfosList;
    }


    /**
     * 校验wpid是否符合要求
     *
     * @param wpid
     * @return
     */
    private Boolean checkWpid(String wpid, Date begainTime, Date endTime) {
        boolean flag = false;
        WpHandleLog wpHandleLog = new WpHandleLog();
        wpHandleLog.setEndTime(endTime);
        wpHandleLog.setBegainTime(begainTime);
        wpHandleLog.setWpid(wpid);
        List<WpHandleLog> wpHandleLogs = wpHandleLogMapper.selectWpHandleLogListByWpidAndTime(wpHandleLog);
        WpHandleLog wpHandleLog1 = wpHandleLogs.stream().filter(dto -> "承办单位处理".equals(dto.getNextState()))
                .max(Comparator.comparing(WpHandleLog::getUpdateTime)).orElse(null);

        WpHandleLog wpHandleLog2 = wpHandleLogs.stream().filter(dto -> "审核人收回工单".equals(dto.getLastState()))
                .max(Comparator.comparing(WpHandleLog::getUpdateTime)).orElse(null);
        if (wpHandleLog1 != null && wpHandleLog2 != null && wpHandleLog2.getUpdateTime().compareTo(wpHandleLog1.getUpdateTime()) > 0) {
            flag = true;
        }
        return flag;
    }

    @Override
    public List<WpInfo> findWpInfoListByWpids(List<String> wpidsCon) {
        List<WpInfo> wpInfos = wpInfoMapper.selectWpInfoByWpids(wpidsCon);
        for (WpInfo info : wpInfos) {

            String class1 = info.getClass1();
            String class2 = info.getClass2();
            String class3 = info.getClass3();
            String class4 = info.getClass4();

            StringBuffer name = new StringBuffer();

            if (StringUtils.isNotEmpty(class1)) {
                SysCode sysCode = sysCodeMapper.selectSysCodeByAutoId(Long.valueOf(class1));
                info.setMainNodename(sysCode.getNodename());
            }

            if (StringUtils.isNotEmpty(class2)) {
                SysCode sysCode = sysCodeMapper.selectSysCodeByAutoId(Long.valueOf(class2));
                name.append(sysCode.getNodename());
            }
            if (StringUtils.isNotEmpty(class3)) {
                SysCode sysCode = sysCodeMapper.selectSysCodeByAutoId(Long.valueOf(class3));
                name.append("/").append(sysCode.getNodename());
            }
            if (StringUtils.isNotEmpty(class4)) {
                SysCode sysCode = sysCodeMapper.selectSysCodeByAutoId(Long.valueOf(class4));
                name.append("/").append(sysCode.getNodename());
            }
            if (StringUtils.isNotEmpty(name)) {
                info.setChildNodeName(name.toString());
            }
        }
        return wpInfos;
    }

    /**
     * 根据天数去除节假日返回对应日期
     *
     * @param date
     * @param day
     * @return
     */
    @Override
    public Date checkOntime(Date date, Integer day, List<String> dates) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");

        SimpleDateFormat formatCon = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String lasetDate = "";
        for (int i = 1; i <= day; i++) {
            lasetDate = addDay(date, i);
            if (dates.contains(lasetDate)) {
                day++;
            }
        }
        Date parseCon = null;
        try {
            Date parse = simpleDateFormat.parse(lasetDate);
            String format = DateFormatUtils.format(parse, "yyyy-MM-dd 23:59:59");
            parseCon = formatCon.parse(format);
        } catch (ParseException e) {
            throw new BaseException("日期转换错误！");
        }
        return parseCon;

    }


    /**
     * @param date 日期
     * @return 加算后的日期
     * @Description 参数的日期加指定的日
     */
    public static String addDay(Date date, int day) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        if (date == null) {
            return null;
        }
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.DATE, day);

        return simpleDateFormat.format(calendar.getTime());
    }

}

